import { deepClone, formatDate } from '../../common/utils';
import { DELIVERY_TYPE_VALUE, ACTIVITY_STATUS_VALUE } from '../../constants/activity';

/**
 * 处理签到周期
 */
export const getSigninPeriod = (typeInfo) => {
    let awardList = [];
    for(let i = 0; i < typeInfo.continuous; i ++) {
        awardList.push({
            day: i + 1,
            award: i + 1 === typeInfo.continuous ? typeInfo.awardReachMaxCoins : typeInfo.awardOnceCoins,
        });
    }
    return awardList;
};

/**
 * 处理默认签到信息
 * @param ownerInfo 拥有者信息
 */
export const dealSigninDefaultData = (ownerInfo = {}) => {
    return {
        name: '每日签到',
        tel: ownerInfo.tel,
        background: '',
        intro: [
            { type: 'text', resource: '' }
        ],
        activityProductWithSkus: [],
        warehouseIds: [],
        deliveryModes: [DELIVERY_TYPE_VALUE.express],
        processStatus: ACTIVITY_STATUS_VALUE.processing,
        checkIn1: {
            continuous: 7,
            awardOnceCoins: 5,
            awardReachMaxCoins: 25,
        },
    };
};

/**
 * 处理签到保存数据
 * @param {Object} signinInfo
 */
export const dealSigninSaveData = (signinInfo) => {
    signinInfo = deepClone(signinInfo);
    // activityProductWithSkus
    signinInfo.activityProductWithSkus = signinInfo.activityProductWithSkus.map(ps => {
        ps.quantity -= 0;
        ps.skus = ps.skus.map(s => {
            s.price -= 0;
            s.maximum -= 0;
            return s;
        });
        return ps;
    });
    delete signinInfo.processStatus;
    delete signinInfo.brandId;
    delete signinInfo.pubUserId;
    delete signinInfo.qualifyTypes;
    delete signinInfo.processStatus;
    delete signinInfo.published;
    delete signinInfo.verifyQualification;
    delete signinInfo.owner;
    return signinInfo;
};
